package Queue;

import java.util.ArrayDeque;

public class MyQueueUseStack {
    public ArrayDeque<Integer> stack1;
    public ArrayDeque<Integer> stack2;

    public MyQueueUseStack(){
        stack1 = new ArrayDeque<>();
        stack2 = new ArrayDeque<>();
    }

    public boolean empty(){
        return stack1.isEmpty() && stack2.isEmpty();
    }

    public void push(int x){
        stack1.push(x);
    }

    public int pop(){
        if (empty()){
            return -1;
        }

        if (stack2.isEmpty()){
            //第一个栈里面的元素放到第二个栈当中
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public int peek(){
        if (empty()){
            return -1;
        }

        if (stack2.isEmpty()){
            //第一个栈里面的元素放到第二个栈当中
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }
}
